home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab4.zip / LRMRDR / LRM_CHAP.ZIP / CHAP09.DOC < prev    next >
Text File  |  1992-04-21  |  57KB  |  1,374 lines

  1. >                                  9. Tasks
  2.  
  3.  
  4. The execution of a program that does not contain a task is defined in terms
  5. of a sequential execution of its actions, according to the rules  described
  6. in  other  chapters  of this manual.  These actions can be considered to be
  7. executed by a single logical processor.
  8.  
  9.  
  10. Tasks are entities whose executions proceed in parallel  in  the  following
  11. sense.   Each  task can be considered to be executed by a logical processor
  12. of  its  own.   Different  tasks  (different  logical  processors)  proceed
  13. independently, except at points where they synchronize.
  14.  
  15.  
  16. Some  tasks have entries.  An entry of a task can be called by other tasks.
  17. A task accepts a call  of  one  of  its  entries  by  executing  an  accept
  18. statement for the entry.  Synchronization is achieved by rendezvous between
  19. a  task  issuing an entry call and a task accepting the call.  Some entries
  20. have parameters;  entry calls and accept statements for  such  entries  are
  21. the principal means of communicating values between tasks.
  22.  
  23.  
  24. The  properties of each task are defined by a corresponding task unit which
  25. consists of a task specification and a task body.  Task units  are  one  of
  26. the  four  forms  of  program  unit of which programs can be composed.  The
  27. other forms are subprograms, packages and generic units.  The properties of
  28. task units,  tasks,  and  entries,  and  the  statements  that  affect  the
  29. interaction   between   tasks  (that  is,  entry  call  statements,  accept
  30. statements, delay statements, select statements, and abort statements)  are
  31. described in this chapter.
  32.  
  33. Note:
  34.  
  35.  
  36. Parallel   tasks  (parallel  logical  processors)  may  be  implemented  on
  37. multicomputers, multiprocessors, or with interleaved execution on a  single
  38. physical  processor.   On  the  other  hand, whenever an implementation can
  39. detect that the same effect can be guaranteed if parts of the actions of  a
  40. given  task  are  executed  by  different  physical  processors  acting  in
  41. parallel, it may choose to execute them in  this  way;   in  such  a  case,
  42. several physical processors implement a single logical processor.
  43.  
  44.  
  45. References:   abort  statement  9.10, accept statement 9.5, delay statement
  46. 9.6, entry 9.5, entry call statement  9.5,  generic  unit  12,  package  7,
  47. parameter  in  an  entry  call  9.5, program unit 6, rendezvous 9.5, select
  48. statement 9.7, subprogram 6, task body 9.1, task specification 9.1
  49.  
  50. > 9.1  Task Specifications and Task Bodies
  51.  
  52.  
  53. A task unit consists of a task specification  and  a  task  body.   A  task
  54. specification  that  starts  with  the reserved words  task type declares a
  55. task type.  The value of an object of a task type designates a task  having
  56. the  entries,  if  any, that are declared in the task specification;  these
  57. entries are also called entries of this object.  The execution of the  task
  58. is defined by the corresponding task body.
  59.  
  60.  
  61. A  task specification without the reserved word type defines a single task.
  62. A task declaration with this form of specification  is  equivalent  to  the
  63. declaration   of  an  anonymous  task  type  immediately  followed  by  the
  64. declaration of an object of the task type, and  the  task  unit  identifier
  65. names the object.  In the remainder of this chapter, explanations are given
  66. in  terms  of  task  type declarations;  the corresponding explanations for
  67. single task declarations follow from the stated equivalence.
  68.  
  69.  
  70.     task_declaration ::= task_specification;
  71.  
  72.     task_specification ::=
  73.        task [type] identifier [is
  74.           {entry_declaration}
  75.           {representation_clause}
  76.        end [task_simple_name]]
  77.  
  78.     task_body ::=
  79.         task body task_simple_name is
  80.            [declarative_part]
  81.         begin
  82.             sequence_of_statements
  83.        [exception
  84.             exception_handler
  85.            {exception_handler}]
  86.         end [task_simple_name];
  87.  
  88.  
  89. The simple name at the start of a task  body  must  repeat  the  task  unit
  90. identifier.   Similarly  if  a  simple  name appears at the end of the task
  91. specification or body, it must repeat the task unit identifier.   Within  a
  92. task  body,  the  name  of  the corresponding task unit can also be used to
  93. refer to the task object that designates the task currently  executing  the
  94. body;   furthermore,  the  use  of  this name as a type mark is not allowed
  95. within the task unit itself.
  96.  
  97.  
  98. For the  elaboration  of  a  task  specification,  entry  declarations  and
  99. representation  clauses,  if  any, are elaborated in the order given.  Such
  100. representation clauses only apply to  the  entries  declared  in  the  task
  101. specification (see 13.5).
  102.  
  103.  
  104. The  elaboration  of a task body has no other effect than to establish that
  105. the body can from then on be used for the execution of tasks designated  by
  106. objects of the corresponding task type.
  107.  
  108.  
  109. The  execution of a task body is invoked by the activation of a task object
  110. of the corresponding type (see 9.3).  The optional  exception  handlers  at
  111. the end of a task body handle exceptions raised during the execution of the
  112. sequence of statements of the task body (see 11.4).
  113.  
  114.  
  115. Examples of specifications of task types:
  116.  
  117.     task type RESOURCE is
  118.        entry SEIZE;
  119.        entry RELEASE;
  120.     end RESOURCE;
  121.  
  122.     task type KEYBOARD_DRIVER is
  123.        entry READ (C : out CHARACTER);
  124.        entry WRITE(C : in  CHARACTER);
  125.     end KEYBOARD_DRIVER;
  126.  
  127.  
  128. Examples of specifications of single tasks:
  129.  
  130.     task PRODUCER_CONSUMER is
  131.        entry READ (V : out ITEM);
  132.        entry WRITE(E : in  ITEM);
  133.     end;
  134.  
  135.     task CONTROLLER is
  136.        entry REQUEST(LEVEL)(D : ITEM);  --  a family of entries
  137.     end CONTROLLER;
  138.  
  139.     task USER;  --  has no entries
  140.  
  141.  
  142. Example of task specification and corresponding body:
  143.  
  144.     task PROTECTED_ARRAY is
  145.        --  INDEX and ITEM are global types
  146.        entry READ (N : in INDEX; V : out ITEM);
  147.        entry WRITE(N : in INDEX; E : in  ITEM);
  148.     end;
  149.  
  150.     task body PROTECTED_ARRAY is
  151.        TABLE : array(INDEX) of ITEM := (INDEX => NULL_ITEM);
  152.     begin
  153.        loop
  154.           select
  155.              accept READ (N : in INDEX; V : out ITEM) do
  156.                 V := TABLE(N);
  157.              end READ;
  158.           or
  159.              accept WRITE(N : in INDEX; E : in  ITEM) do
  160.                 TABLE(N) := E;
  161.              end WRITE;
  162.           end select;
  163.        end loop;
  164.     end PROTECTED_ARRAY;
  165.  
  166. Note:
  167.  
  168.  
  169. A task specification specifies the interface of tasks of the task type with
  170. other  tasks  of  the  same  or  of different types, and also with the main
  171. program.
  172.  
  173.  
  174. References:  declaration 3.1, declarative part 3.9, elaboration 3.9,  entry
  175. 9.5,  entry  declaration  9.5, exception handler 11.2, identifier 2.3, main
  176. program 10.1, object 3.2, object declaration 3.2.1,  representation  clause
  177. 13.1,  reserved word 2.9, sequence of statements 5.1, simple name 4.1, type
  178. 3.3, type declaration 3.3.1
  179.  
  180. > 9.2  Task Types and Task Objects
  181.  
  182.  
  183. A task type is a limited type (see 7.4.4).  Hence  neither  assignment  nor
  184. the  predefined  comparison  for  equality  and  inequality are defined for
  185. objects of task types;  moreover, the mode out is not allowed for a  formal
  186. parameter whose type is a task type.
  187.  
  188.  
  189. A  task object is an object whose type is a task type.  The value of a task
  190. object designates a task that has the entries  of  the  corresponding  task
  191. type,  and whose execution is specified by the corresponding task body.  If
  192. a task object is the object, or a subcomponent of the object,  declared  by
  193. an  object declaration, then the value of the task object is defined by the
  194. elaboration of the object declaration.  If a task object is the object,  or
  195. a  subcomponent  of  the object, created by the evaluation of an allocator,
  196. then the value of the task object is  defined  by  the  evaluation  of  the
  197. allocator.   For  all  parameter modes, if an actual parameter designates a
  198. task, the associated formal parameter designates the same task;   the  same
  199. holds  for  a  subcomponent  of  an  actual parameter and the corresponding
  200. subcomponent of the associ